local skel = fk.CreateSkill {
  name = "emo__baoshi",
}

Fk:loadTranslationTable{
  ["emo__baoshi"] = "暴食",
  [":emo__baoshi"] = "出牌阶段限一次，你可以用弃牌堆随机牌与至多三名角色拼点，若有没赢的角色，重复以此法与其拼点。",
  ["#emo__baoshi-prompt"] = "暴食：与至多三名角色拼点",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#emo__baoshi-prompt",
  card_num = 0,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected)
    return #selected < 3 and player:canPindian(to_select, true)
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
    and #Fk:currentRoom().discard_pile > 0
    and table.find(Fk:currentRoom().alive_players, function (p)
      return player:canPindian(p, true)
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = table.simpleClone(effect.tos)
    while not player.dead and #tos > 0 do
      local pile = room.discard_pile
      if #pile == 0 then break end
      local myCard = Fk:getCardById(table.random(pile))
      local pindian = player:pindian(tos, skel.name, myCard)
      if player.dead then return end
      local losers = {}
      for _, p in ipairs(tos) do
        if pindian.results[p].winner ~= p then
          table.insert(losers, p)
        end
      end
      if #losers == 0 then break end
      player.room:delay(600)
      tos = table.filter(losers, function(p) return not p.dead and player:canPindian(p, true) end)
    end
  end,
})

return skel
